package com.ldc.wandroid.adapter;

import android.widget.TextView;

import androidx.annotation.NonNull;

import com.donkingliang.labels.LabelsView;
import com.ldc.common.common.CommonRecyclerView;
import com.ldc.common.common.CommonRecyclerViewHolder;
import com.ldc.wandroid.R;
import com.ldc.wandroid.model.SystemModel;

import java.util.ArrayList;
import java.util.Random;

public class SystemAdapter extends CommonRecyclerView<SystemModel> {
    private LabelsView.OnLabelClickListener onLabelClickListener;

    public SystemAdapter() {
        super(R.layout.layout_item_system);
    }

    public void setOnLabelClickListener(LabelsView.OnLabelClickListener onLabelClickListener) {
        this.onLabelClickListener = onLabelClickListener;
    }


    @Override
    protected void convert2Data(@NonNull CommonRecyclerViewHolder holder, SystemModel systemModel, int position) {
        holder.setText(R.id.tvTitle, systemModel.getName());
        final ArrayList<String> labs = new ArrayList<>(16);
        if (null == systemModel.getChildren()) return;
        for (SystemModel.ChildrenBean c : systemModel.getChildren()) {
            if (null == c) continue;
            labs.add(c.getName());
        }
        ((LabelsView) holder.findViewById(R.id.labels)).setLabels(labs);
        ((LabelsView) holder.findViewById(R.id.labels)).setOnLabelClickListener((label, data, position1) -> {
            if (null != onLabelClickListener) {
                onLabelClickListener.onLabelClick(label, systemModel.getChildren().get(position1), position1);
            }
        });

    }
}
